﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Data;
using System.Data.SqlClient;
public partial class _Default : System.Web.UI.Page
{
    #region variable
    SqlDataReader dr = null;
    SqlCommand cmd;
    Dataconnect conn = new Dataconnect();
    string strPass;
    #endregion
    #region method
    protected void ChangePass()
    {
        try
        {
            strPass = Encript.mahoa(txt_pass2.Text);
            cmd = new SqlCommand();
            cmd.CommandText = "CusChagPass";
            cmd.Connection = conn.Connect();
            cmd.CommandType = CommandType.StoredProcedure;
            cmd.Parameters.AddWithValue("@user", Session["CustomerName"].ToString());
            cmd.Parameters.AddWithValue("@pass", strPass);
            if (cmd.ExecuteNonQuery() > 0)
            {
                Response.Write("<script>alert('Change password successfully !!.')</script>");
               // 
            }
            else
            {
                Response.Write("<script>alert('error!!.')</script>");
            }
            Response.Redirect("LogIn Customer.aspx");
        }
        catch (Exception ex)
        {
            Response.Write("<script>alert('"+ex+"')</script>");
        }
    }
  
    #endregion
    protected void Page_Load(object sender, EventArgs e)
    {
        if (!IsPostBack)
        {
            if (Session["CustomerName"] != null)
            {
                hlink_logIn.Visible = false;
                linkbn_logout.Visible = true;
                linkbtn_register.Visible = false;
                name.Text = Session["CustomerName"].ToString();
               
            }
            else
            {
                Response.Redirect("LogIn Customer.aspx");
                hlink_logIn.Visible = true;
                linkbtn_register.Visible = true;
                name.Text = null;
            }
        }
    }

    protected void Button1_Click(object sender, EventArgs e)
    {
        if (txt_pass.Text != "")
        {
            ChangePass();
        }
        else {
            Label_error.Visible = true;
            Label_error.Text = "password is not null";
            
        }
    }
    protected void ImageButton1_Click(object sender, ImageClickEventArgs e)
    {
        Response.Redirect("Cart.aspx");
    }
    protected void linkbn_logout_Click(object sender, EventArgs e)
    {
      //  Session["CustomerName"] = null;
        Response.Redirect("LogIn Customer.aspx");
    }
    protected void linkbtn_register_Click(object sender, EventArgs e)
    {
        Response.Redirect("Register.aspx");
    }
}